package cn.lili.modules.order.order.entity.vo;

import cn.lili.common.security.context.UserContext;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 订单流水统计
 *
 * @author Chopper
 * @since 2020/11/17 7:31 下午
 */
@Data
@ApiModel(value = "订单流水统计")
public class OrderFlowStatisticsVO {

    @ApiModelProperty(value = "流水总金额")
    private Double flowPrice;

    @ApiModelProperty(value = "退款总金额")
    private Double refundPrice;

    @ApiModelProperty(value = "已结算总金额")
    private Double settledPrice;

    @ApiModelProperty(value = "店铺结算金额")
    private Double sellerSettlementPrice = 0D;

    @ApiModelProperty(value = "店铺已结算金额")
    private Double sellerSettledPrice = 0D;

    @ApiModelProperty(value = "供应商结算金额")
    private Double supplierSettlementPrice = 0D;

    @ApiModelProperty(value = "供应商已结算金额")
    private Double supplierSettledPrice = 0D;


    @ApiModelProperty(value = "分销商返现支出")
    private Double distributorSettlementPrice = 0D;

    @ApiModelProperty(value = "分销商已结算金额")
    private Double distributorSettledPrice = 0D;


    @ApiModelProperty(value = "平台利润结算金额")
    private Double platformSettlementPrice;

    @ApiModelProperty(value = "平台利润已结算金额")
    private Double platformSettledPrice = 0D;


    /**
     * 设置已结算订单流水统计
     *
     * @param orderFlowStatisticsVO 订单流水统计
     */
    public void setSettledOrderFlow(OrderFlowStatisticsVO orderFlowStatisticsVO) {
        if (orderFlowStatisticsVO == null) {
            return;
        }
        this.settledPrice = orderFlowStatisticsVO.getFlowPrice();
        this.refundPrice = orderFlowStatisticsVO.getRefundPrice();
        this.sellerSettledPrice = orderFlowStatisticsVO.getSellerSettlementPrice();
        this.distributorSettledPrice = orderFlowStatisticsVO.getDistributorSettlementPrice();
        this.platformSettledPrice = orderFlowStatisticsVO.getPlatformSettlementPrice();
        this.supplierSettledPrice = orderFlowStatisticsVO.getSupplierSettlementPrice();
    }

    public OrderFlowStatisticsVO filter() {
        switch (UserContext.getCurrentUser().getScene()) {
            case MANAGER, URBAN_SUBSTATION -> {
                return this;
            }
            case STORE -> {
                this.setSupplierSettledPrice(null);
                this.setSupplierSettlementPrice(null);
                this.setFlowPrice(null);
                this.setRefundPrice(null);
                this.setPlatformSettlementPrice(null);
                this.setPlatformSettledPrice(null);
                return this;
            }
            case SUPPLIER -> {
                this.setFlowPrice(null);
                this.setRefundPrice(null);
                this.setPlatformSettlementPrice(null);
                this.setPlatformSettledPrice(null);
                this.setDistributorSettledPrice(null);
                this.setDistributorSettlementPrice(null);
                return this;
            }
            default -> throw new IllegalStateException("Unexpected value: " + UserContext.getCurrentUser().getScene());
        }
    }
}